import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import UnoCSS from 'unocss/vite'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vite.dev/config/
export default defineConfig(({ mode })=>{
  const config = loadEnv(mode, './')
  const server = {
      // port: 3000,
      open: true,
      proxy: {},
  }
  server.proxy[config.VITE_API_URL]={
      target: config.VITE_BASE_URL,
      secure: false,
      changeOrigin: true,
      rewrite: (path) => path.replace(config.VITE_API_URL, "")
  }
  return {
    plugins: [
      vue(),
      UnoCSS(),
      AutoImport({
        imports: ['vue', 'vue-router', 'pinia'],
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      UnoCSS({
        configFile:'./uno.config.js'
      }),
    ],
    resolve: {
      alias: {
        '@v': resolve(__dirname, 'src/views/'),
        '@c': resolve(__dirname, 'src/components'),
        '@u': resolve(__dirname, 'src/utils'),
        '@a': resolve(__dirname, 'src/assets'),
        '@api': resolve(__dirname, 'src/api'),
        '@r': resolve(__dirname, 'src/router'),
        '@s': resolve(__dirname, 'src/store'),
        '@': resolve(__dirname, 'src'),
      },
    },
    server,
  }
})
